#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:homework5_4.py
# author:wmf
# datetime:2021/4/14 20:30
# software: PyCharm
'''
this is function description
'''
# import module your need

# 4  编写装饰器来实现，对目标函数进行装饰,计算函数的运行耗时，
#     分3种情况：目标函数无参数无返回值，目标函数有参数，目标函数有返回值；
#      三个目标函数分别为：
#      A 打印输出20000之内的素数；
#      B 计算整数2-10000之间的素数的个数；
#      C 计算整数2-M之间的素数的个数；
#   可以观看给的视频材料，仿照示例来做；
import math
import time


def get_time(func):
    def inner(*args, **kw):
        start_time = time.time()
        res = func(*args, **kw)
        end_time = time.time()
        Time = end_time - start_time
        print("run time is %ss"%Time)
        return res
    return inner


@get_time
def print_prime1():
    prime = []
    for x in range(2,20000):
        count = 0
        for i in range(2,int(math.sqrt(x)) + 1):
            if x%i != 0:
                continue
            else:
                count = count + 1
        if count == 0:
            prime.append(x)
    print(prime)


print_prime1()


@get_time
def print_prime2(n):
    prime = []
    for x in range(2, n+1):
        count = 0
        for i in range(2, int(math.sqrt(x)) + 1):
            if x % i != 0:
                continue
            else:
                count = count + 1
        if count == 0:
            prime.append(x)
    print(prime)


print_prime2(20000)


@get_time
def print_prime3():
    prime = []
    for x in range(2, 20000):
        count = 0
        for i in range(2, int(math.sqrt(x)) + 1):
            if x % i != 0:
                continue
            else:
                count = count + 1
        if count == 0:
            prime.append(x)
    return prime


print(print_prime3())